<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class raovat_model extends CI_Model
{
	function __construct(){
        parent::__construct();
	}
	
	function get_all($num=30, $offset=0,$member_id=0)
	{
		$this->db->where('bl_active',1);
		if($member_id) $this->db->where('member_id', $member_id);
		$this->db->order_by('dt_modify','DESC');
		$query = $this->db->get('raovat', $num, $offset);
		return $query->result();
	}
	
	function count_all($member_id=0)
	{      
		 //$this->db->where('bl_active',1);
		 if($member_id) $this->db->where('member_id', $member_id);
		 $query = $this->db->get('raovat');
		 return $query->num_rows();
	}

	
	function get_all_category($class_id, $num=20,$offset=0)
	{
		$this->db->where('class_id',$class_id);	
		$this->db->where('bl_active',1);	
		$this->db->order_by('dt_create','DESC');
		$query = $this->db->get('raovat',$num, $offset);
		return $query->result() ;	
	}
	
	function count_all_category($class_id)
	{
		$this->db->where('class_id',$class_id);
		$this->db->where('bl_active',1);
		$query = $this->db->get('raovat');
		return $query->num_rows();
	}
	
	function get_id($id)
	{
		$this->db->where('raovat_id',$id);	
		//$this->db->where('bl_active',1);
		$query = $this->db->get('raovat');
		return $query->row();	
		
	}
	
	function get_last_news($mid, $num=20, $offset=0)
	{
		$this->db->where('bl_active',1);
		$this->db->where('mID',$mid);
		$this->db->order_by('dt_create','DESC');//'DESC'
		return $this->db->get('raovat',$num, $offset)->result();
	}

	function save($table, $req, $wh='', $value=0)
	{
		if(!empty($value))
		{
			$this->db->where($wh, $value) ;
			return $this->db->update($table, $req) ;
		}
		else
		{
			$this->db->insert($table, $req) ;
			return $this->db->insert_id() ;
		}
	}


}
?>
